package main

import "fmt"

func main() {
	fmt.Println("1、-------start-----------")
	var nums []int
	printSliceIn("numbers:",nums)

	nums = append(nums,0)
	printSliceIn("append(nums,0):",nums)

	nums = append(nums,1,2,34,5,67)
	printSliceIn("append(nums,1,2,34,5,67):",nums)

	s1:=[]int{100,200,300,400,500,600,700}
	nums = append(nums,s1...) //append slice
	printSliceIn("append(nums,s1...):",nums)

	fmt.Println("2、-------delete----------")

	nums = nums[1:]
	printSliceIn("nums[1:]:",nums)

	nums = nums[:len(nums)-1]
	printSliceIn("nums[:len(nums)-1]:",nums)

	a:=int(len(nums)/2)
	fmt.Println("中间下标a：",a)
	nums = append(nums[:a],nums[a+1:]...)
	printSliceIn("append(nums[:a],nums[a+1:]...):",nums)

	fmt.Println("3、-------create target slice----------")
	nums1 := make([]int,len(nums),cap(nums)*2)

	//copy nums to nums1
	count := copy(nums1,nums)
	fmt.Println("拷贝的个数：count = ",count)
	printSliceIn("copy(nums1,nums)",nums1)

	//update value
	nums[0] = 99
	nums1[len(nums1)-1] = 100

	printSliceIn("修改的nums: ",nums)
	printSliceIn("修改的nums1: ",nums1)
}

func printSliceIn(name string,x []int)  {
	fmt.Print(name,"\t")
	fmt.Printf("地址：%p \t len=%d \t cap=%d \t value=%v \n",x,len(x),cap(x),x)

}
